import axios from './axios'
import qs from 'qs'

export function getCustomer() {
    const data = qs.stringify({pageSize: 100000});
    return axios.post('/customer/manage/get_customer_list_by_param.do', data).then(res => Promise.resolve(res.data))
}

export function addCustomer(customer) {
    const data = qs.stringify(customer);
    return axios.post('/customer/manage/add_customer.do', data).then(res => Promise.resolve(res.data))
}

export function modCustomer(customer) {
    const data = qs.stringify(customer);
    return axios.post('/customer/manage/update_customer.do', data).then(res => Promise.resolve(res.data));
}

export function changeCustomerStatus({customerId, status}) {
    const data = qs.stringify({customerId, status});
    return axios.post('/customer/manage/disable_customer.do', data).then(res => Promise.resolve(res.data))
}

export function getSpecCustomer() {
    return axios.get('/special_customer/manage/select_special_customer.do').then(res => Promise.resolve(res.data))
}

export function getCustomerEmployee(customerId) {
    return axios.post('/special_customer/manage/select_receiver.do', qs.stringify({customerId})).then(res => Promise.resolve(res.data))
}

export function addContact(contact) {
    return axios.post('/special_customer/manage/save_customer_contact.do', qs.stringify(contact)).then(res => Promise.resolve(res.data))
}

export function modContact(contact) {
    return axios.post('/special_customer/manage/update_customer_contact.do', qs.stringify(contact)).then(res => Promise.resolve(res.data))
}

export function addSpecCustomer({customerName}) {
    return axios.post('/special_customer/manage/add_customer_special.do', qs.stringify({customerName})).then(res => Promise.resolve(res.data))
}

export function modSpecCustomer({id, customerName}) {
    return axios.post('/special_customer/manage/update_customer_special.do', qs.stringify({
        id,
        customerName
    })).then(res => Promise.resolve(res.data))
}

export function deleteSpecCustomer(id) {
    return axios.post('/special_customer/manage/delete_customer_contact.do', qs.stringify({id})).then(res => Promise.resolve(res.data))
}

export function getAddressList(customerId) {
    return axios.post('/address/manage/get_customer_address.do', qs.stringify({customerId})).then(res => Promise.resolve(res.data))
}

export function addAddress({customerId, address, addressAbbr, phone, positionLongitude, positionLatitude}) {
    const data = qs.stringify({customerId, address, addressAbbr, phone, positionLongitude, positionLatitude});
    return axios.post('/address/manage/add_customer_address.do', data).then(res => Promise.resolve(res.data))
}

export function modAddress({customerId, address, addressAbbr, phone, addressId, positionLongitude, positionLatitude}) {
    const data = qs.stringify({
        customerId,
        address,
        addressAbbr,
        phone,
        addressId,
        positionLongitude,
        positionLatitude
    });
    return axios.post('/address/manage/update_customer_address.do', data).then(res => Promise.resolve(res.data))
}

export function getContactList(customerId) {
    return axios.post('/contact/manage/get_customer_contact.do', qs.stringify({customerId})).then(res => Promise.resolve(res.data))
}

export function addContactMan({customerId, contactName, sex, jobPosition, mainJobContent, email, phones}) {
    const data = qs.stringify({customerId, contactName, sex, jobPosition, mainJobContent, email, phones});
    return axios.post('/contact/manage/add_customer_contact.do', data).then(res => Promise.resolve(res.data))
}

export function modContactMan({customerId, contactName, sex, jobPosition, mainJobContent, email, phones, contactId}) {
    const data = qs.stringify({customerId, contactName, sex, jobPosition, mainJobContent, email, phones, contactId});
    return axios.post('/contact/manage/update_customer_contact.do', data).then(res => Promise.resolve(res.data))
}
